﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace SAD
{
    class DonacionR
    {
        //Atributos que se van a usar para llenar el panel correspondiente a la opcion "Buscar"
        private System.Windows.Forms.DataGridView dvgDonacionR;
        private TextBox txtBoxBuscar;
        DataSet dtData = new DataSet();
        private Label label1Buscar, label2Buscar;
        private ComboBox combo1Buscar;

        //Atributos que se van a usar para llenar el panel correspondiente a la opcion "NUEVO"
        System.Windows.Forms.GroupBox groupBox1Nuevo;
        System.Windows.Forms.RichTextBox richTextBox1Nuevo;
        System.Windows.Forms.Label label3Nuevo;
        System.Windows.Forms.TextBox textBox1Nuevo;
        System.Windows.Forms.Label label2Nuevo;
        System.Windows.Forms.GroupBox groupBox2Nuevo;
        System.Windows.Forms.TextBox textBox2Nuevo;
        System.Windows.Forms.Label label4Nuevo;
        System.Windows.Forms.DateTimePicker dateTimePicker1Nuevo;
        System.Windows.Forms.Label label1Nuevo, label5Nuevo;
        System.Windows.Forms.Button buttonRegistrarNuevo;

        public void llenarPanelNuevo(Panel pan)
        {
            System.Windows.Forms.GroupBox groupBox1;
            System.Windows.Forms.RichTextBox richTextBox1;
            System.Windows.Forms.Label label3;
            System.Windows.Forms.TextBox textBox1;
            System.Windows.Forms.Label label2;
            System.Windows.Forms.GroupBox groupBox2;
            System.Windows.Forms.TextBox textBox2;
            System.Windows.Forms.Label label4;
            System.Windows.Forms.DateTimePicker dateTimePicker1;
            System.Windows.Forms.Label label1, label5;
            System.Windows.Forms.Button buttonRegistrar;
            
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VentanaDonacion));
            groupBox1 = new System.Windows.Forms.GroupBox();
            richTextBox1 = new System.Windows.Forms.RichTextBox();
            label3 = new System.Windows.Forms.Label();
            textBox1 = new System.Windows.Forms.TextBox();
            label2 = new System.Windows.Forms.Label();
            groupBox2 = new System.Windows.Forms.GroupBox();
            textBox2 = new System.Windows.Forms.TextBox();
            label4 = new System.Windows.Forms.Label();
            dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
            label1 = new System.Windows.Forms.Label();
            buttonRegistrar = new System.Windows.Forms.Button();
            label5 = new Label();
            groupBox1.SuspendLayout();
            groupBox2.SuspendLayout();
            
            //
            //groupBox1
            //
            groupBox1.BackColor = System.Drawing.Color.Transparent;
            groupBox1.Controls.Add(richTextBox1);
            groupBox1.Controls.Add(label3);
            groupBox1.Controls.Add(textBox1);
            groupBox1.Controls.Add(label2);
            groupBox1.Location = new System.Drawing.Point(11, 50);
            groupBox1.Name = "groupBox1";
            groupBox1.Size = new System.Drawing.Size(320, 128);
            groupBox1.TabIndex = 0;
            groupBox1.TabStop = false;
            groupBox1.Text = "Datos Generales";
            //
            //richTextBox1
            //
            richTextBox1.Location = new System.Drawing.Point(103, 64);
            richTextBox1.Name = "richTextBox1";
            richTextBox1.Size = new System.Drawing.Size(199, 43);
            richTextBox1.TabIndex = 5;
            richTextBox1.Text = "";
            //
            //label3
            //
            label3.AutoSize = true;
            label3.Location = new System.Drawing.Point(17, 63);
            label3.Name = "label3";
            label3.Size = new System.Drawing.Size(63, 13);
            label3.TabIndex = 4;
            label3.Text = "Descripcion";
            //
            //textBox1
            //
            textBox1.Location = new System.Drawing.Point(103, 23);
            textBox1.Name = "textBox1";
            textBox1.ReadOnly = true;
            textBox1.Size = new System.Drawing.Size(143, 20);
            textBox1.TabIndex = 3;
            //
            //label2
            //
            label2.AutoSize = true;
            label2.Location = new System.Drawing.Point(17, 26);
            label2.Name = "label2";
            label2.Size = new System.Drawing.Size(62, 13);
            label2.TabIndex = 2;
            label2.Text = "IdDonacion";
            //
            //groupBox2
            //
            groupBox2.BackColor = System.Drawing.Color.Transparent;
            groupBox2.Controls.Add(textBox2);
            groupBox2.Controls.Add(label4);
            groupBox2.Controls.Add(dateTimePicker1);
            groupBox2.Controls.Add(label1);
            groupBox2.Location = new System.Drawing.Point(12, 190);
            groupBox2.Name = "groupBox2";
            groupBox2.Size = new System.Drawing.Size(318, 92);
            groupBox2.TabIndex = 1;
            groupBox2.TabStop = false;
            groupBox2.Text = "Datos Especificos";
            // 
            // textBox2
            // 
            textBox2.Location = new System.Drawing.Point(102, 53);
            textBox2.Name = "textBox2";
            textBox2.Size = new System.Drawing.Size(98, 20);
            textBox2.TabIndex = 5;
            // 
            // label4
            // 
            label4.AutoSize = true;
            label4.Location = new System.Drawing.Point(16, 56);
            label4.Name = "label4";
            label4.Size = new System.Drawing.Size(53, 13);
            label4.TabIndex = 4;
            label4.Text = "Donatario";
            // 
            // dateTimePicker1
            // 
            dateTimePicker1.Location = new System.Drawing.Point(101, 23);
            dateTimePicker1.Name = "dateTimePicker1";
            dateTimePicker1.Size = new System.Drawing.Size(200, 20);
            dateTimePicker1.TabIndex = 3;
            // 
            // label1
            // 
            label1.AutoSize = true;
            label1.Location = new System.Drawing.Point(16, 29);
            label1.Name = "label1";
            label1.Size = new System.Drawing.Size(79, 13);
            label1.TabIndex = 2;
            label1.Text = "Fecha Registro";
            // 
            // buttonRegistrar
            // 
            buttonRegistrar.Location = new System.Drawing.Point(137, 300);
            buttonRegistrar.Name = "buttonRegistrar";
            buttonRegistrar.Size = new System.Drawing.Size(75, 23);
            buttonRegistrar.TabIndex = 2;
            buttonRegistrar.Text = "Registrar";
            buttonRegistrar.UseVisualStyleBackColor = true;

            //
            //label5
            //

            label5.AutoSize = true;
            label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            label5.Location = new System.Drawing.Point(200, 20);
            label5.Name = "label5";
            label5.Size = new System.Drawing.Size(11, 24);
            label5.TabIndex = 9;
            label5.Text = "Nueva Donacion";

            pan.Controls.Add(buttonRegistrar);
            pan.Controls.Add(label5);
            pan.Controls.Add(groupBox1);
            pan.Controls.Add(groupBox2);
            groupBox1.ResumeLayout(false);
            groupBox1.PerformLayout();
            groupBox2.ResumeLayout(false);
            groupBox2.PerformLayout();

            buttonRegistrar.Click += new EventHandler(buttonRegistrar_click);

            groupBox1Nuevo = groupBox1;
            richTextBox1Nuevo = richTextBox1;
            label3Nuevo = label3;
            textBox1Nuevo = textBox1;
            label2Nuevo = label2;
            groupBox2Nuevo = groupBox2;
            textBox2Nuevo = textBox2;
            label4Nuevo = label4;
            dateTimePicker1Nuevo = dateTimePicker1;
            label1Nuevo = label1;
            label5Nuevo = label5;
            buttonRegistrarNuevo = buttonRegistrar;

        }
        public void llenarPanelBuscar(Panel pan)
        {
            //Grid para llenar la tabla de emergencias
            this.dvgDonacionR = new DataGridView();
            this.dvgDonacionR.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dvgDonacionR.Location = new System.Drawing.Point(30, 150);
            this.dvgDonacionR.Name = "dvgDonacionR";
            this.dvgDonacionR.Size = new System.Drawing.Size(543, 242);
            this.dvgDonacionR.TabIndex = 9;

            //Texto donde va a ir el campo de la tabla que se va a buscar
            this.txtBoxBuscar = new TextBox();
            this.txtBoxBuscar.Location = new Point(30, 110);
            this.txtBoxBuscar.Name = "txtBoxBuscar";
            this.txtBoxBuscar.Size = new Size(200, 20);
            this.txtBoxBuscar.KeyPress += new KeyPressEventHandler(txtBoxBuscar_KeyPress);

            //label1Buscar Cabecera del "txtBoxBuscar"
            this.label1Buscar = new Label();
            this.label1Buscar.AutoSize = true;
            this.label1Buscar.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1Buscar.Location = new Point(30, 90);
            this.label1Buscar.Text = "Nombre del campo: ";
            //this.label1Buscar.Size = new Size(28, 13);

            //label2Buscar Cabecera del combo "combo1Buscar"
            this.label2Buscar = new Label();
            this.label2Buscar.AutoSize = true;
            this.label2Buscar.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2Buscar.Location = new Point(30, 30);
            this.label2Buscar.Text = "Buscar por:";
            //this.label2Buscar.Size = new Size(28, 13);

            //combo1Buscar es el combo box que indica sobre qué campo de la tabla se va a realizar la busqueda
            this.combo1Buscar = new ComboBox();
            this.combo1Buscar.Location = new Point(30, 60);
            this.combo1Buscar.Size = new System.Drawing.Size(150, 21);
            this.combo1Buscar.FormattingEnabled = true;
            this.combo1Buscar.Items.Add("Codigo de campaña");
            //this.combo1Buscar.Items.Add("Fecha");
            this.combo1Buscar.Items.Add("Codigo de Ubicacion");
            this.combo1Buscar.SelectedItem = "Codigo de Emergencia";

            //datos auxiliares
            string sqlCad;
            sqlCad = "select idEmergencia as Codigo_Emergencia, fecha as Fecha, lugar as Lugar, tipo as Tipo, prioridad as Prioridad, idUbicacion as Codigo_Ubicacion";
            sqlCad = sqlCad + " from Emergencia";
            SqlDataAdapter sqlAdap;

            //Aqui se va a llenar un grid con la data de la tabla "Emergencia"
            try
            {
                sqlAdap = new SqlDataAdapter(sqlCad, Conexion.connection);
                sqlAdap.Fill(this.dtData);
                this.dvgDonacionR.DataSource = this.dtData.Tables[0];
            }
            catch
            {
                MessageBox.Show("Error de conexion a al BD");
            }

            pan.Controls.Add(label2Buscar);
            pan.Controls.Add(combo1Buscar);
            pan.Controls.Add(label1Buscar);
            pan.Controls.Add(txtBoxBuscar);
            pan.Controls.Add(dvgDonacionR);
        }

        //Este metodo se encarga de hacer una busqueda a lo GOOGLE =) osea mientras se va escribiendo el texto del campo que estas buscando
        //El grid va mostrando las filas que coinciden con lo escrito hasta el momento.

        private void txtBoxBuscar_KeyPress(object sender, KeyPressEventArgs e)
        {
            string strCad;
            string campoSeleccionado = "";
            if (e.KeyChar != Convert.ToChar(Keys.Back))
                strCad = txtBoxBuscar.Text + e.KeyChar;
            else
            {
                if (txtBoxBuscar.Text.Length > 0)
                    strCad = txtBoxBuscar.Text.Substring(0, txtBoxBuscar.Text.Length - 1);
                else
                    strCad = txtBoxBuscar.Text;
            }
            DataView dv;


            if (combo1Buscar.SelectedItem == "Codigo de Donacion")
                campoSeleccionado = "Codigo_Emergencia";
            else if (combo1Buscar.SelectedItem == "Codigo de Ubicacion")
                campoSeleccionado = "Codigo_Ubicacion";

            dv = new DataView(this.dtData.Tables[0], campoSeleccionado + " like'%" + strCad + "%'", "Codigo_Emergencia", DataViewRowState.CurrentRows);
            this.dvgDonacionR.DataSource = dv;
        }

        private void buttonRegistrar_click(object sender, EventArgs e)
        {

        }

       
    }
}
